package com.aaa.order.controller;

import com.aaa.order.feign.ProductFeign;
import com.aaa.order.service.OrderService;
import com.aaa.pojo.Order;
import com.aaa.pojo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Random;

/**
 * @program: qy163-parent
 * @description:
 * @author: 闫克起2
 * @create: 2023-05-12 16:30
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private ProductFeign productFeign;

    @GetMapping("save")
    public String save(Integer pid,Integer num){
        //springcloud 扫描到@FeignClient注解后，就会为改注解接口生成一个代理实现类，再把代理实现类注册改相应的属性
//        System.out.println("~~~~~~~~~~~~~~~~~"+productFeign);
        Order order = new Order();
        //用户信息--登录中获取
        order.setUid(1);
        order.setUsername("李云宵");
        order.setNumber(num);

        Product product = productFeign.getById(pid);
        if(product==null){
            return "下单失败";
        }
        order.setPid(product.getPid());
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());
        orderService.save(order);
        return "下单成功";
    }
}
